﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using JCTimes.DomainModel.Views;
using JCTimes.EFRepository.Specification;
using JCTimes.Portal.Infrastructure;
using System.Data.SqlClient;

namespace JCTimes.Portal.Specification
{
    public class PDALogSpecification
    {
        public static Expression<Func<V_PDALog, bool>> Get_V_Lst_PDALog_Pred(Searcher searcher)
        {
            Specification<V_PDALog> spec = new TrueSpecification<V_PDALog>();
            foreach (var key in searcher.Keys)
            {
                switch (key)
                {
                    case "pdano":
                        string pdano = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDALog>(x => x.PDANo != null && x.PDANo.Contains(pdano));
                        break;
                    case "connectflag":
                        string connectflag = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDALog>(x => x.ConnectFlag != null && x.ConnectFlag == connectflag);
                        break;
                    case "startdate":
                        DateTime startdate = Convert.ToDateTime(searcher[key].Trim());
                        spec &= new DirectSpecification<V_PDALog>(x => x.CreateDate != null && x.CreateDate >= startdate);
                        break;
                    case "enddate":
                        DateTime enddate = Convert.ToDateTime(searcher[key].Trim());
                        spec &= new DirectSpecification<V_PDALog>(x => x.CreateDate != null && x.CreateDate <= enddate);
                        break;
             
                    default:
                        break;
                }
            }

            return spec.SatisfiedBy();
        }
    }
}